package com.yixing.tech.wcs.tcp;

import com.yixing.tech.common.tcp.manage.EndpointManager;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class EndpointConfiguration {

    @Resource
    InteractionConsumer interactionConsumer;

    private static final DeviceAddrConfig deviceAddrConfig = new DeviceAddrConfig();

    private static String endpointId;

    public static void setDeviceAddrConfig(String ip, String port) {
        deviceAddrConfig.setIp(ip);
        deviceAddrConfig.setPort(port);
    }

    public static DeviceAddrConfig getDeviceAddrConfig() {
        return deviceAddrConfig;
    }

    public static void setEndpointId(String endpointId) {
        EndpointConfiguration.endpointId = endpointId;
    }

    public static String getEndpointId() {
        return endpointId;
    }

    @Bean
    public EndpointManager endpointManager() {
        return new EndpointManager();
    }

//    @Primary
//    @Bean(name = "consumeFunction")
//    public Function<TcpMessage, TcpReply> consumeFunction() {
//        return msg -> interactionConsumer.consume(msg);
//    }

    @Data
    @ToString
    @NoArgsConstructor
    public static class DeviceAddrConfig {
        private String ip;
        private String port;
    }
}
